package com.example.demo.nuoqi.service.impl;

import com.example.demo.nuoqi.dao.MyapplicationMapper;
import com.example.demo.nuoqi.pojo.Myapplication;
import com.example.demo.nuoqi.service.MyapplicationService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/****
 * @Author:shenkunlin
 * @Description:Myapplication业务层接口实现类
 * @Date 2019/6/14 0:16
 *****/
@Service
public class MyapplicationServiceImpl implements MyapplicationService {

    @Autowired
    private MyapplicationMapper myapplicationMapper;


    /**
     * Myapplication条件+分页查询
     * @param myapplication 查询条件
     * @param page 页码
     * @param size 页大小
     * @return 分页结果
     */
    @Override
    public PageInfo<Myapplication> findPage(Myapplication myapplication, int page, int size){
        //分页
        PageHelper.startPage(page,size);
        //搜索条件构建
        Example example = createExample(myapplication);
        //执行搜索
        return new PageInfo<Myapplication>(myapplicationMapper.selectByExample(example));
    }

    /**
     * Myapplication分页查询
     * @param page
     * @param size
     * @return
     */
    @Override
    public PageInfo<Myapplication> findPage(int page, int size){
        //静态分页
        PageHelper.startPage(page,size);
        //分页查询
        return new PageInfo<Myapplication>(myapplicationMapper.selectAll());
    }

    /**
     * Myapplication条件查询
     * @param myapplication
     * @return
     */
    @Override
    public List<Myapplication> findList(Myapplication myapplication){
        //构建查询条件
        Example example = createExample(myapplication);
        //根据构建的条件查询数据
        return myapplicationMapper.selectByExample(example);
    }


    /**
     * Myapplication构建查询对象
     * @param myapplication
     * @return
     */
    public Example createExample(Myapplication myapplication){
        Example example=new Example(Myapplication.class);
        Example.Criteria criteria = example.createCriteria();
        if(myapplication!=null){
            // 
            if(!StringUtils.isEmpty(myapplication.getId())){
                    criteria.andEqualTo("id",myapplication.getId());
            }
            // 
            if(!StringUtils.isEmpty(myapplication.getItemName())){
                    criteria.andEqualTo("itemName",myapplication.getItemName());
            }
            // 
            if(!StringUtils.isEmpty(myapplication.getItemId())){
                    criteria.andEqualTo("itemId",myapplication.getItemId());
            }
            // 
            if(!StringUtils.isEmpty(myapplication.getCreateName())){
                    criteria.andEqualTo("createName",myapplication.getCreateName());
            }
            // 
            if(!StringUtils.isEmpty(myapplication.getCreateTime())){
                    criteria.andEqualTo("createTime",myapplication.getCreateTime());
            }
            // 
            if(!StringUtils.isEmpty(myapplication.getStatus())){
                    criteria.andEqualTo("status",myapplication.getStatus());
            }
        }
        return example;
    }

    /**
     * 删除
     * @param id
     */
    @Override
    public void delete(Integer id){
        myapplicationMapper.deleteByPrimaryKey(id);
    }

    /**
     * 修改Myapplication
     * @param myapplication
     */
    @Override
    public void update(Myapplication myapplication){
        myapplicationMapper.updateByPrimaryKey(myapplication);
    }

    /**
     * 增加Myapplication
     * @param myapplication
     */
    @Override
    public void add(Myapplication myapplication){
        myapplicationMapper.insert(myapplication);
    }

    /**
     * 根据ID查询Myapplication
     * @param id
     * @return
     */
    @Override
    public Myapplication findById(Integer id){
        return  myapplicationMapper.selectByPrimaryKey(id);
    }

    /**
     * 查询Myapplication全部数据
     * @return
     */
    @Override
    public List<Myapplication> findAll() {
        return myapplicationMapper.selectAll();
    }
}
